﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;

namespace EveruWPF.Windows.Helpers
{
    public class UserControlHelper
    {
        #region IsWindowDraggerProperty
        public static readonly DependencyProperty IsWindowDraggerProperty = DependencyProperty.RegisterAttached("IsWindowDragger", typeof(bool), typeof(UIElement), new PropertyMetadata(new PropertyChangedCallback(IsWindowDraggerChanged)));

        static void IsWindowDraggerChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            try
            {
                UIElement elmn = (UIElement)sender;
                Window wnd = Window.GetWindow(sender);

                elmn.MouseDown += (object sender2, System.Windows.Input.MouseButtonEventArgs e2) =>
                    {
                        if (e2.ChangedButton == System.Windows.Input.MouseButton.Left)
                            try
                            {
                                wnd.DragMove();
                            }
                            catch { }
                    };

            }
            catch { }
        }

        public static void SetIsWindowDragger(UIElement element, bool value)
        {
            element.SetValue(IsWindowDraggerProperty, value);
        }

        public static bool GetIsWindowDragger(UIElement element)
        {
            return (bool)element.GetValue(IsWindowDraggerProperty);
        } 
        #endregion



    }
}
